<?php

class SettingsController extends Controller
{
	public function actionIndex()
	{
		//$this->render('index');
		 $settings = Yii::app()->settings;
		 
        $model = new SettingsForm();
 
        if (isset($_POST['SettingsForm'])) {
            $model->setAttributes($_POST['SettingsForm']);
            $settings->deleteCache();
            foreach($model->attributes as $category => $values){
                $settings->set($category, $values);
            }
            //user()->setFlash('success', 'Site settings were updated.');
            $this->refresh();
        }
        foreach($model->attributes as $category => $values){
            $cat = $model->$category;
            foreach($values as $key=>$val){
                $cat[$key] = $settings->get($category, $key);
            }
            $model->$category = $cat;
        }
        $this->render('index', array('model' => $model)); 
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}